package com.zs.test.mvpdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.zs.test.mvpdemo.presenter.LoginPresenter;
import com.zs.test.mvpdemo.presenter.LoginPresenterImpl;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity implements LoginView {

    @BindView(R.id.username)
    EditText username;
    @BindView(R.id.password)
    EditText password;
    @BindView(R.id.button)
    Button button;
    @BindView(R.id.progress)
    ProgressBar progress;

    private LoginPresenter mLoginPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        mLoginPresenter = new LoginPresenterImpl(this);


    }

    @OnClick(R.id.button)
    public void onClick() {
        mLoginPresenter.checkLogin(username.getText().toString(),password.getText().toString());

    }

    @Override
    public void showProgress() {
        progress.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideProgress() {
        progress.setVisibility(View.GONE);
    }

    @Override
    public void setUserNameError() {
        username.setText("name error");
    }

    @Override
    public void setPassWordError() {

        password.setText("psd error");
    }

    @Override
    public void toHome() {
        Toast.makeText(this, "yes", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onDestroy() {
        mLoginPresenter.clearLogin();
        super.onDestroy();
    }
}
